import 'package:flutter/material.dart';
import './PPCommdityColumnItemView.dart';
import '../model/PPShopHomePageModel.dart';

class PPCommdityColumnView extends StatefulWidget {

    PPCommdityColumnView(Map<String, List<PPCommodityModel>> data, {Key key , this.onPressAction}): this.data = data, super(key: key);

    final Map<String, List<PPCommodityModel>>  data;
    final Function onPressAction;

    _PPCommdityColumnViewState createState() => _PPCommdityColumnViewState();
}

class _PPCommdityColumnViewState extends State<PPCommdityColumnView> {

    Map<String, List<PPCommodityModel>> data;

    @override
    void initState() {
        data = widget.data;
        super.initState();
    }

    @override
    void didUpdateWidget(PPCommdityColumnView oldWidget) {
        data = widget.data;
        super.didUpdateWidget(oldWidget);
    }

    @override
    Widget build(BuildContext context) {
        List<PPCommodityModel> leftColumn = data['leftColumn'];
        List<PPCommodityModel> rightColumn = data['rightColumn'];
        return Container(
            padding: EdgeInsets.fromLTRB(12.5, 0, 12.5, 10),
            child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                    Container(
                        alignment: Alignment.topLeft,
                        margin: EdgeInsets.fromLTRB(0, 0, 10, 0),
                        child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: _getColumnItems(leftColumn)
                        )
                    ),
                    Container(
                        child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: _getColumnItems(rightColumn)
                        )
                    ),
                ],
            ),
        );
    }

    List<Widget> _getColumnItems( List<PPCommodityModel>  list) {
        return list.map((item){
        return PPCommdityColumnItemView(item, onClickAction: _onPressCommdityItem);
        }).toList();   
    }

    _onPressCommdityItem(PPCommodityModel item) {
        if(widget.onPressAction != null){
            widget.onPressAction(item);
        }
    }

}
